package com.centit.framework.ip.businessdata.dao;

import com.centit.framework.core.dao.CodeBook;
import com.centit.framework.ip.businessdata.po.TodoItem;
import com.centit.framework.jdbc.dao.BaseDaoImpl;
import com.centit.framework.jdbc.dao.DatabaseOptUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;


/**
 * TodoItemDao  Repository.
 * create by scaffold 2018-06-04
 *
 * @author guo_jh
 * T_TODO_ITEM各个系统待办事项数据表
 */

@Repository
public class TodoItemDao extends BaseDaoImpl<TodoItem, String> {

    public static final Log log = LogFactory.getLog(TodoItemDao.class);

    @Override
    public Map<String, String> getFilterField() {
        if (filterField == null) {
            filterField = new HashMap<String, String>();

            filterField.put("recId", CodeBook.EQUAL_HQL_ID);


            filterField.put("itemName", CodeBook.LIKE_HQL_ID);

            filterField.put("systemId", CodeBook.EQUAL_HQL_ID);

            filterField.put("itemUrl", CodeBook.EQUAL_HQL_ID);

            filterField.put("itemState", CodeBook.IN_HQL_ID);

            filterField.put("createTime", CodeBook.EQUAL_HQL_ID);

            filterField.put("updateTime", CodeBook.EQUAL_HQL_ID);

            filterField.put("isValid", CodeBook.EQUAL_HQL_ID);

            filterField.put("userCode", CodeBook.EQUAL_HQL_ID);

            filterField.put("childRecId", CodeBook.EQUAL_HQL_ID);

        }
        return filterField;
    }

    /**
     * 根据子系统待办事项ID更新待办数据为已办
     * 待阅件需要根据用户一个个更新
     * @param id 子系统事项ID
     * @return 操作结果
     */
    public int updateObject(String id) {
        String sql = " UPDATE T_TODO_ITEM T SET T.ISVALID = 'F', T.UPDATETIME = SYSDATE WHERE T.CHILD_REC_ID = ? and nvl(T.ITEMSTATE,'null')<>'dyj'";
        int result = DatabaseOptUtils.doExecuteSql(this, sql, new Object[]{id});
        return result;
    }
}
